package exception;

public class Person {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age)  {

        if (age < 0 || age > 100) {
            // 抛出异常IllegalArgumentException 是 RuntimeException  子类
            // IllegalArgumentException 也是 运行异常

            //throw new IllegalArgumentException("[年龄必须在0--100之间]。Age must be between 0 and 100");
           // 抛出一个非运行异常，该方法上就必须添加 throws 抛出这个异常
           // throw new Exception("[年龄必须在0--100之间]");
            // 抛出自己定义的业务异常
            throw  new IllegalAgeException("[年龄必须在0--100之间]");
        }
        this.age = age;
    }
}
